package com.itfreer.special.report;

import com.itfreer.form.api.JdbcBaseDaoImp;
import org.springframework.stereotype.Component;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 定义报表数据定义 jdbc实现类
 */
@Component
public class JdbcReportDictionaryDao extends JdbcBaseDaoImp<ReportDictionaryEntity> implements ReportDictionaryDao {
	public JdbcReportDictionaryDao(EntityManager entityManager) {
		super(ReportDictionaryEntity.class, entityManager);
	}

	@SuppressWarnings("unchecked")
	public List<LinkedHashMap<String, Object>> getTableList(String tableName, String fieldName, String where) {
		// 自定义查询
		List<LinkedHashMap<String, Object>> list = null;
		try {
			String sql = "select " + fieldName + " from " + tableName + where;
			Query query = em.createNativeQuery(sql);
//			query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.TO_LIST);
			list = query.getResultList();
		} catch (Exception var5) {
			throw var5;
		}
		return list;
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getTableField(String tableName) {
		// 自定义查询
		List<Map<String, Object>> list = null;
		try {
			String sql = "SELECT column_name FROM information_schema.columns WHERE table_name='" + tableName + "'";
			Query query = em.createNativeQuery(sql);
//			query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
			list = query.getResultList();
		} catch (Exception var5) {
			throw var5;
		}
		return list;
	}
}
